package com.michale.common.constants;

import io.swagger.annotations.ApiModelProperty;

/**
 * @author Michale
 * @apiNote redis缓存的key 常量
 */
public class RedisCacheConstant {

    @ApiModelProperty("登录用户 redisKey")
    public static final String LOGIN_TOKEN_KEY = "login_tokens:";

    @ApiModelProperty("登录用户 redisKey")
    public static final String LOGIN_KEY = "login:";
    @ApiModelProperty("验证码 redisCacheKey ")
    public static final String CAPTCHA_CODE_KEY = "captcha_codes:";

    @ApiModelProperty("参数管理 redisCacheKey")
    public static final String SYS_CONFIG_KEY = "sys_config:";

    @ApiModelProperty("字典管理 redisCacheKey")
    public static final String SYS_DICT_KEY = "sys_dict:";

    @ApiModelProperty("防重提交 redisCacheKey")
    public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";

    @ApiModelProperty("限流 redisCacheKey")
    public static final String RATE_LIMIT_KEY = "rate_limit:";

    @ApiModelProperty("登录账户密码错误次数 redisCacheKey")
    public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";

    @ApiModelProperty("加锁脚本")
    public static final String LOCK_LUA = "if redis.call('setNx',KEYS[1],ARGV[1]) == 1 then return redis.call('expire',KEYS[1],ARGV[2]) else return 0 end";

    @ApiModelProperty("解锁脚本")
    public static final String RELEASE_LOCK_LUA = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";

    @ApiModelProperty("限流脚本")
    public static final String LIMITER_LUA =  "local key = KEYS[1] local count = tonumber(ARGV[1]) local time = tonumber(ARGV[2]) local current = redis.call('get', key); if current and tonumber(current) > count then return tonumber(current); end current = redis.call('incr', key) if tonumber(current) == 1 then redis.call('expire', key, time) end return tonumber(current)";
}
